package com.byq.mm.smartlib.tools;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.byq.mm.smartlib.R;
public class ModeArrayAdapter extends ArrayAdapter<String> {

	Activity context;

	String[] names;
	int[] icons;
	Object[] data;

	//int resource;


	public ModeArrayAdapter(Activity context, int resource, String[] names, int[] icons, Object[] data) {
		super(context, resource, names);
		this.context = context;
		this.names = names;
		this.icons = icons;
		this.data = data;
	
		
		//this.resource = resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = context.getLayoutInflater();
		View row = inflater.inflate(R.layout.spinner_view, null, false);
		if(position >= names.length)
			return row;
		TextView label = (TextView)row.findViewById(R.id.spinner_item);
		
		label.setText(names[position]);
		ImageView icon = (ImageView)row.findViewById(R.id.spinner_pic);

		icon.setImageResource(icons[position]);
	
		row.setTag(data[position]);

		return row;
	}
	
	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {

		View row = convertView;
		
		if(row==null) {		
			LayoutInflater inflater = context.getLayoutInflater();
			row = inflater.inflate(R.layout.spinner_view_dropdown, null, false);
			if(position >= names.length)
				return row;
			row.setTag(data[position]);
		}
		TextView label = (TextView)row.findViewById(R.id.spinner_item);
		
		label.setText(names[position]);
		ImageView icon = (ImageView)row.findViewById(R.id.spinner_pic);
		
		icon.setImageResource(icons[position]);
		return row;
	}

}
